﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/Administration.Master" AutoEventWireup="true"
    CodeBehind="RoleManagement2.aspx.cs" Inherits="ASB.CC.Web.Admin.RoleManagement2" %>

<%@ Register Src="../UserControls/Pager.ascx" TagName="Pager" TagPrefix="cc" %>
<asp:Content ContentPlaceHolderID="Header" runat="server">
    <style>
        .menu-h2
        {
            font-weight: bold;
        }
        .menu-h3
        {
            padding-left: 25px;
        }
        .pcat-flow, .country-flow
        {
            display: inline-block;
            width: 255px;
            float: left;
        }
        #menu-switch, #page-switch, #pcat-switch, #country-switch
        {
            background-color: #efebfa;
            cursor: pointer;
            text-align: center;
        }
    </style>

    <script src="../js/jquery-1.4.4.min.js" type="text/javascript"></script>

    <script src="../js/jquery-ui.min.js" type="text/javascript"></script>

    <script src="../js/entity.js.aspx" type="text/javascript"></script>

    <script type="text/javascript">
        $(function() {
            $("#menu,#page,#pcat,#country").tabs();

            $("#menu-switch,#page-switch,#pcat-switch,#country-switch").bind("click", function() {
                var tab = $(this).next();
                if (tab.data("display") == null)
                    tab.data("display", true);
                if (tab.data("display")) {
                    tab.hide(500);
                    tab.data("display", false);
                }
                else {
                    tab.show(500);
                    tab.data("display", true);
                }
            });


            $("#menu-switch").click();
            $("#page-switch").click();
            $("#pcat-switch").click();
            $("#country-switch").click();
        });
    </script>

</asp:Content>
<asp:Content ContentPlaceHolderID="Sitemap" runat="server">
    &nbsp;&raquo;&nbsp;Administration&nbsp;&raquo;&nbsp;Role Management
</asp:Content>
<asp:Content ContentPlaceHolderID="Tab" runat="server">
    <%=Resources.PageTitles.RoleManagement %>
</asp:Content>
<asp:Content ContentPlaceHolderID="Utility" runat="server">
    <div class="formbox_float_lft">
        <asp:Button ID="btnAdd" runat="server" CssClass="entity-add" />
    </div>
    <div class="formbox_float_rgt">
        <asp:TextBox ID="txtSearch" runat="server" CssClass="txtbox width140 entity-search-text"
            ToolTip="Role Name"></asp:TextBox>
        <asp:Button ID="btnSearch" runat="server" CssClass="entity-search" />
        <asp:Button ID="btnClear" runat="server" CssClass="entity-clear" />
    </div>
</asp:Content>
<asp:Content ContentPlaceHolderID="Main" runat="server">
    <%--GridView--%>
    <asp:GridView ID="gvMain" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False"
        DataSourceID="edsMain" DataKeyNames="RoleID" CssClass="tablestyle">
        <RowStyle CssClass="tbody" />
        <HeaderStyle CssClass="thead" ForeColor="#ffffff" />
        <Columns>
            <asp:BoundField DataField="Name" HeaderText="Role Name<br/>角色名称" SortExpression="Name"
                HtmlEncode="false" ItemStyle-Width="20%" />
            <asp:BoundField DataField="Description" HeaderText="Description<br/>角色描述" SortExpression="Description"
                HtmlEncode="false" ItemStyle-Width="43%" />
            <asp:BoundField DataField="BelongsTo" HeaderText="Module<br/>类属模块" SortExpression="BelongsTo"
                HtmlEncode="false" ItemStyle-Width="15%" />
           <%-- <asp:BoundField DataField="IsAdmin" HeaderText="Is Admin<br/>是否为管理员" SortExpression="IsAdmin"
                HtmlEncode="false" ItemStyle-Width="15%" />--%>
            <asp:TemplateField HeaderText="Is Admin<br/>是否为管理员">
            <ItemTemplate>
               <asp:Label ID="IsAdmin" runat="server" Text='<%# GetIsAdmin(Eval("IsAdmin"))%>' />
            </ItemTemplate>
            <ItemStyle Width="15%" />
            </asp:TemplateField>
            <asp:ActionField HeaderText="Action<br />操作" ShowViewButton="true" ShowModifyButton="true"
                ShowDisableButton="true" HeaderStyle-CssClass="entity-action" ItemStyle-Width="60"/>
        </Columns>
        <PagerTemplate>
            <cc:Pager runat="server" />
        </PagerTemplate>
    </asp:GridView>
    <%--DetailsView--%>
    <asp:DetailsView ID="dvMain" runat="server" AutoGenerateRows="False" DataKeyNames="RoleID"
        DataSourceID="edsMain" DefaultMode="Edit" CssClass="tablestyle2">
        <HeaderStyle CssClass="tablestyle2_Title"></HeaderStyle>
        <HeaderTemplate>
            <%=Resources.PageTitles.RoleManagement%>
        </HeaderTemplate>
        <FieldHeaderStyle CssClass="tablestyle2_tdTitle" />
        <Fields>
            <asp:TemplateField HeaderText="Module (所属模块)" ItemStyle-CssClass="entity-selects-check">
                <ItemTemplate>
                    <%#Eval("BelongsTo") %>
                </ItemTemplate>
                <InsertItemTemplate>
                    <asp:DropDownList ID="ddlModule" runat="server" SelectedValue='<%#Bind("BelongsTo") %>'
                        DataSource='<%#GetBelongsToList() %>' />
                </InsertItemTemplate>
                <EditItemTemplate>
                    <asp:DropDownList ID="ddlModule" runat="server" SelectedValue='<%#Bind("BelongsTo") %>'
                        DataSource='<%#GetBelongsToList() %>' />
                </EditItemTemplate>
            </asp:TemplateField>
            <asp:CustomizeBoundField DataField="Name" HeaderText="Role Name (角色名称)" ItemStyle-CssClass="entity-notnull-check entity-length-check"
                MaxLength="50" />
            <asp:CustomizeBoundField DataField="Description" HeaderText="Description (描述)" ItemStyle-CssClass="entity-length-check"
                MaxLength="50" />
            <asp:TemplateField HeaderText="Is Admin (是否为管理员)">
                <ItemTemplate>
                    <%#Eval("IsAdmin")%>
                </ItemTemplate>
                <InsertItemTemplate>
                    <asp:CheckBox ID="cbIsAdmin" runat="server" Checked='<%#Bind("IsAdmin")%>' />
                </InsertItemTemplate>
                <EditItemTemplate>
                    <asp:CheckBox ID="cbIsAdmin" runat="server" Checked='<%#Bind("IsAdmin")%>' />
                </EditItemTemplate>
            </asp:TemplateField>
            <%--Menus--%>
            <asp:TemplateField HeaderText="Menus (菜单项配置)">
                <ItemTemplate>
                    <div id="menu-switch">
                        Expand/Collapse Menus</div>
                    <div id="menu">
                        <asp:Repeater runat="server" DataSource='<%#GetMenus(EvalX("Menus")) %>'>
                            <ItemTemplate>
                                <div class="menu-h2">
                                    <%#Eval("Name") %>
                                    [<%#Eval("Description") %>]</div>
                                <asp:Repeater runat="server" DataSource='<%#Eval("Children") %>'>
                                    <ItemTemplate>
                                        <div class="menu-h3">
                                            <%#Eval("Name") %>
                                            [<%#Eval("Description") %>]</div>
                                    </ItemTemplate>
                                </asp:Repeater>
                            </ItemTemplate>
                        </asp:Repeater>
                    </div>
                </ItemTemplate>
                <EditItemTemplate>
                    <div id="menu-switch">
                        Expand/Collapse Menus</div>
                    <div id="menu">
                        <ul>
                            <asp:Repeater runat="server" DataSource='<%#GetModules() %>'>
                                <ItemTemplate>
                                    <li><a href="#menu-<%#GetDataItem() %>">
                                        <%#GetDataItem() %></a></li>
                                </ItemTemplate>
                            </asp:Repeater>
                        </ul>
                        <asp:Repeater runat="server" DataSource='<%#GetModules(EvalX("Menus")) %>'>
                            <ItemTemplate>
                                <div id="menu-<%#Eval("Module") %>">
                                    <asp:Repeater runat="server" DataSource='<%#GetMenuRelation(Eval("Data"), Eval("Module")) %>'>
                                        <ItemTemplate>
                                            <div class="menu-h2">
                                                <%#Eval("Name") %>
                                                [<%#Eval("Description") %>]</div>
                                            <asp:Repeater runat="server" DataSource='<%#Eval("Children") %>'>
                                                <ItemTemplate>
                                                    <div class="menu-h3">
                                                        <input type="checkbox" name="menucheck" value="<%# Eval("MenuID") %>" <%#Eval("Checked") %> /><%#Eval("Name") %>
                                                        [<%#Eval("Description") %>]</div>
                                                </ItemTemplate>
                                            </asp:Repeater>
                                        </ItemTemplate>
                                    </asp:Repeater>
                                </div>
                            </ItemTemplate>
                        </asp:Repeater>
                    </div>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <div id="menu-switch">
                        Expand/Collapse Menus</div>
                    <div id="menu">
                        <ul>
                            <asp:Repeater runat="server" DataSource='<%#GetModules() %>'>
                                <ItemTemplate>
                                    <li><a href="#menu-<%#GetDataItem() %>">
                                        <%#GetDataItem() %></a></li>
                                </ItemTemplate>
                            </asp:Repeater>
                        </ul>
                        <asp:Repeater runat="server" DataSource='<%#GetModules() %>'>
                            <ItemTemplate>
                                <div id="menu-<%#GetDataItem() %>">
                                    <asp:Repeater runat="server" DataSource='<%#GetMenuRelation(null, GetDataItem()) %>'>
                                        <ItemTemplate>
                                            <div class="menu-h2">
                                                <%#Eval("Name") %>
                                                [<%#Eval("Description") %>]</div>
                                            <asp:Repeater runat="server" DataSource='<%#Eval("Children") %>'>
                                                <ItemTemplate>
                                                    <div class="menu-h3">
                                                        <input type="checkbox" name="menucheck" value="<%# Eval("MenuID") %>" /><%#Eval("Name") %>
                                                        [<%#Eval("Description") %>]</div>
                                                </ItemTemplate>
                                            </asp:Repeater>
                                        </ItemTemplate>
                                    </asp:Repeater>
                                </div>
                            </ItemTemplate>
                        </asp:Repeater>
                    </div>
                </InsertItemTemplate>
            </asp:TemplateField>
            <%--AspxPages--%>
            <asp:TemplateField HeaderText="Page Access (页面访问)">
                <ItemTemplate>
                    <div id="page-switch">
                        Expand/Collapse Pages</div>
                    <div id="page">
                        <asp:Repeater runat="server" DataSource='<%#GetPages(EvalX("AspxPages")) %>'>
                            <ItemTemplate>
                                <div>
                                    <%#Eval("FullName") %>
                                    [<%# (ASBCC.Business.AccessLevel)Eval("AccessLevel")%>]</div>
                            </ItemTemplate>
                        </asp:Repeater>
                    </div>
                </ItemTemplate>
                <EditItemTemplate>
                    <div id="page-switch">
                        Expand/Collapse Pages</div>
                    <div id="page">
                        <ul>
                            <asp:Repeater runat="server" DataSource='<%#GetModules() %>'>
                                <ItemTemplate>
                                    <li><a href="#page-<%#GetDataItem() %>">
                                        <%#GetDataItem() %></a></li>
                                </ItemTemplate>
                            </asp:Repeater>
                        </ul>
                        <asp:Repeater runat="server" DataSource='<%#GetModules(EvalX("AspxPages")) %>'>
                            <ItemTemplate>
                                <div id="page-<%#Eval("Module") %>">
                                    <asp:Repeater runat="server" DataSource='<%#GetPageRelation(Eval("Data"), Eval("Module")) %>'>
                                        <ItemTemplate>
                                            <div>
                                                <input type="checkbox" name="pagecheck" value="<%# Eval("PageID") %>" <%# Eval("Checked") %> />
                                                <%#Eval("FullName") %>
                                                [<%# (ASBCC.Business.AccessLevel)Eval("AccessLevel")%>]</div>
                                        </ItemTemplate>
                                    </asp:Repeater>
                                </div>
                            </ItemTemplate>
                        </asp:Repeater>
                    </div>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <div id="page-switch">
                        Expand/Collapse Pages</div>
                    <div id="page">
                        <ul>
                            <asp:Repeater runat="server" DataSource='<%#GetModules() %>'>
                                <ItemTemplate>
                                    <li><a href="#page-<%#GetDataItem() %>">
                                        <%#GetDataItem() %></a></li>
                                </ItemTemplate>
                            </asp:Repeater>
                        </ul>
                        <asp:Repeater runat="server" DataSource='<%#GetModules() %>'>
                            <ItemTemplate>
                                <div id="page-<%#GetDataItem() %>">
                                    <asp:Repeater runat="server" DataSource='<%#GetPageRelation(null, GetDataItem()) %>'>
                                        <ItemTemplate>
                                            <div>
                                                <input type="checkbox" name="pagecheck" value="<%# Eval("PageID") %>" />
                                                <%#Eval("FullName") %>
                                                [<%# (ASBCC.Business.AccessLevel)Eval("AccessLevel")%>]</div>
                                        </ItemTemplate>
                                    </asp:Repeater>
                                </div>
                            </ItemTemplate>
                        </asp:Repeater>
                    </div>
                </InsertItemTemplate>
            </asp:TemplateField>
            <%--PCATs--%>
            <asp:TemplateField HeaderText="PCATs (所属PCATs)">
                <ItemTemplate>
                    <div id="pcat-switch">
                        Expand/Collapse PCATs</div>
                    <div id="pcat">
                        <asp:Repeater runat="server" DataSource='<%#GetPCATs(EvalX("PCATs")) %>'>
                            <ItemTemplate>
                                <div class="pcat-flow">
                                    <%#Eval("ProvinceName") %><%#Eval("CategoryName") %></div>
                            </ItemTemplate>
                        </asp:Repeater>
                    </div>
                </ItemTemplate>
                <EditItemTemplate>
                    <div id="pcat-switch">
                        Expand/Collapse PCATs</div>
                    <div id="pcat">
                        <asp:Repeater runat="server" DataSource='<%#GetPCATRelation(EvalX("PCATs")) %>'>
                            <ItemTemplate>
                                <div class="pcat-flow">
                                    <input type="checkbox" name="pcatcheck" value="<%# Eval("ProvinceID") %>;<%# Eval("CategoryID") %>"
                                        <%# Eval("Checked") %> />
                                    <%#Eval("ProvinceName") %><%#Eval("CategoryName") %></div>
                            </ItemTemplate>
                        </asp:Repeater>
                    </div>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <div id="pcat-switch">
                        Expand/Collapse PCATs</div>
                    <div id="pcat">
                        <asp:Repeater runat="server" DataSource='<%#GetPCATRelation(null) %>'>
                            <ItemTemplate>
                                <div class="pcat-flow">
                                    <input type="checkbox" name="pcatcheck" value="<%# Eval("ProvinceID") %>;<%# Eval("CategoryID") %>" />
                                    <%#Eval("ProvinceName") %><%#Eval("CategoryName") %></div>
                            </ItemTemplate>
                        </asp:Repeater>
                    </div>
                </InsertItemTemplate>
            </asp:TemplateField>
            <%--Countries--%>
            <asp:TemplateField HeaderText="Countries (所属国家)">
                <ItemTemplate>
                    <div id="country-switch">
                        Expand/Collapse Countires</div>
                    <div id="country">
                        <asp:Repeater runat="server" DataSource='<%#GetCountries(EvalX("Countries")) %>'>
                            <ItemTemplate>
                                <div class="country-flow">
                                    <%#Eval("Name") %>
                                    [<asp:Repeater runat="server" DataSource='<%#GetAreas(Eval("Areas")) %>'>
                                        <ItemTemplate>
                                            <span>
                                                <%#Eval("Name") %></span>
                                        </ItemTemplate>
                                    </asp:Repeater>
                                    ]</div>
                            </ItemTemplate>
                        </asp:Repeater>
                    </div>
                </ItemTemplate>
                <EditItemTemplate>
                    <div id="country-switch">
                        Expand/Collapse Countires</div>
                    <div id="country">
                        <asp:Repeater runat="server" DataSource='<%#GetCountryRelation(EvalX("Countries")) %>'>
                            <ItemTemplate>
                                <div class="country-flow">
                                    <input type="checkbox" name="countrycheck" value="<%# Eval("CountryID") %>" <%# Eval("Checked") %> />
                                    <%#Eval("Name") %>
                                    [<asp:Repeater runat="server" DataSource='<%#GetAreas(Eval("Areas")) %>'>
                                        <ItemTemplate>
                                            <span>
                                                <%#Eval("Name") %></span>
                                        </ItemTemplate>
                                    </asp:Repeater>
                                    ]</div>
                            </ItemTemplate>
                        </asp:Repeater>
                    </div>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <div id="country-switch">
                        Expand/Collapse Countires</div>
                    <div id="country">
                        <asp:Repeater runat="server" DataSource='<%#GetCountryRelation(null) %>'>
                            <ItemTemplate>
                                <div class="country-flow">
                                    <input type="checkbox" name="countrycheck" value="<%# Eval("CountryID") %>" />
                                    <%#Eval("Name") %>
                                    [<asp:Repeater runat="server" DataSource='<%#GetAreas(Eval("Areas")) %>'>
                                        <ItemTemplate>
                                            <span>
                                                <%#Eval("Name") %></span>
                                        </ItemTemplate>
                                    </asp:Repeater>
                                    ]</div>
                            </ItemTemplate>
                        </asp:Repeater>
                    </div>
                </InsertItemTemplate>
            </asp:TemplateField>
            <asp:ActionField ShowEditButton="true" ShowInsertButton="true" ShowInsertMoreButton="true"
                ShowCloseButton="true" />
        </Fields>
    </asp:DetailsView>
    <%--Entity--%>
    <asp:EntityDataSource ID="edsMain" runat="server" ConnectionString="name=CCEntities"
        DefaultContainerName="CCEntities" EnableInsert="True" EnableUpdate="True" EntitySetName="Roles"
        Where="!it.Disabled" Include="Menus,AspxPages,PCATs,Countries" OnInserted="EntityRoles_Inserted"
        OnUpdated="EntityRoles_Updated">
    </asp:EntityDataSource>
</asp:Content>
